package cn.uce.cc.srv.biz.impl;

import cn.uce.base.PubApiObjectConstants;
import cn.uce.base.ccos.OrderPostParamsVo;
import cn.uce.base.ccos.OrderVo;
import cn.uce.cc.api.service.biz.ICcosOrderBiz;
import cn.uce.cc.srv.client.CcosInterfaceClient;
import cn.uce.cc.srv.utils.HttpClientPubApiUtils;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@Service("ccosOrderBiz")
public class CcosOrderBiz implements ICcosOrderBiz {
    private static final Logger log = LoggerFactory.getLogger(CcosOrderBiz.class);

    @Resource
    CcosInterfaceClient ccosInterfaceClient;


    @Override
    public String saveOrder(OrderPostParamsVo orderPostParamsVo) {
        String result = "";
        Map<String, Object> map = new HashMap();
        OrderVo orderVo = orderPostParamsVo.getOrderVo();
        map.put("orderSource", String.valueOf(orderVo.getOrderChannel()));
        map.put("orderVo", orderPostParamsVo.getOrderVo());
        String msg_temp = HttpClientPubApiUtils.buildUpStructure(PubApiObjectConstants.ORDER_POST_FROM_ONLINE, map);
        try {
            log.warn("saveOrder,begin"+ JSON.toJSONString(orderPostParamsVo));
            log.warn("saveOrder,beginmsg_temp"+ msg_temp);
            result =  ccosInterfaceClient.saveOrder(msg_temp);
            log.warn("saveOrder,end"+result);
        } catch (Exception e) {
            log.error("postOrderData出现异常：" + e);
            return e.toString();
        }
        return result;
    }
}